/*
 * $HeadURL: $
 * $Id: $
 * Copyright (c) 2011 by Ericsson, all rights reserved.
 */

package android.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.test.R;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

/**
 *
 * @author xyonton
 * @version $Revision: $
 */
public class ImageAdapterGallery extends BaseAdapter {
    /** Revision of the class */
    public static final String _REV_ID_  = "$Revision: $";

    int                        mGalleryItemBackground;

    private Context            mContext;

    private Integer[]          mImageIds = { R.drawable.background, R.drawable.background, R.drawable.background,
            R.drawable.background       };

    public ImageAdapterGallery(Context c) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
        mGalleryItemBackground = attr.getResourceId(R.styleable.HelloGallery_android_galleryItemBackground, 0);
        attr.recycle();
    }

    public int getCount() {
        return mImageIds.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);

        imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(HelloGallery.screenWidth, HelloGallery.screenHeight));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }

}
